home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / network / atre12.zip / MOSQUITO.ZIP / MOSQWIN.C < prev    next >
C/C++ Source or Header  |  1991-07-05  |  9KB  |  217 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** mosqwin.c                                                           ****
  4.  ****                                                                     ****
  5.  **** Copyright (C) A. Dwelly and W.W. Armstrong, 1990.                   ****
  6.  ****                                                                     ****
  7.  **** All rights reserved.                                                ****
  8.  ****                                                                     ****
  9.  **** Attachment of copyright does not imply publication.                 ****
  10.  **** This file contains information which is proprietary                 ****
  11.  **** to the authors.                                                     ****
  12.  ****                                                                     ****
  13.  **** This is a test of the research version of the adaptive logic        ****
  14.  **** network package atree. This particular program demonstrates the     ****
  15.  **** algorithm's ability to extract a simple relationship from complex   ****
  16.  **** data.                                                               ****
  17.  ****                                                                     ****
  18.  **** Each entry in the training set represents a human about which       ****
  19.  **** 80 facts are known, represented by randomly setting bits. The       ****
  20.  **** function _mosquito()_ is a single bit which is set if the patient   ****
  21.  **** has been bitten by a mosquito (bit 1) is not taking quinine (bit 7) ****
  22.  **** and does not have sickle cell anemia (bit 12). The programer is free****
  23.  **** to increase the difficulty of the experiment by modifying the       ****
  24.  **** initial constants.                                                  ****
  25.  ****                                                                     ****
  26.  **** As the program is set up, the algorithm is searching in a space     ****
  27.  **** of 2^80 bits, that is, 1208925819614629174706176 seperate bit       ****
  28.  **** patterns, from this, it sees a mere 500 (a fraction of 1% of the    ****
  29.  **** possible patterns) but correctly deduces the relationship between   ****
  30.  **** the known facts, and the health of the patients.                    ****
  31.  ****                                                                     ****
  32.  **** The adaptive logic network package based on work done by Prof. W.   ****
  33.  **** W. Armstrong and others in the Department of Computing Science,     ****
  34.  **** University of Alberta, and previous work at the Universite de       ****
  35.  **** Montreal, and at AT&T Bell Laboratories, Holmdel, N. J.  The        ****
  36.  **** software demonstrates that networks consisting of many layers of    ****
  37.  **** linear threshold elements can indeed be effectively trained.        ****
  38.  ****                                                                     ****
  39.  **** License:                                                            ****
  40.  **** A royalty-free license is granted for the use of this software for  ****
  41.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and        ****
  42.  **** modified provided this notice appears in its entirety and unchanged ****
  43.  **** in all copies, whether changed or not.  Persons modifying the code  ****
  44.  **** are requested to state the date, the changes made and who made them ****
  45.  **** in the modification history.                                        ****
  46.  ****                                                                     ****
  47.  **** Warranty:                                                           ****
  48.  **** No warranty of any kind is provided with this software.             ****
  49.  **** This software is not supported.  Neither the authors, nor the       ****
  50.  **** University of Alberta, its officers, agents, servants or employees  ****
  51.  **** shall be liable or responsible in any way for any damage to         ****
  52.  **** property or direct personal or consequential injury of any nature   ****
  53.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  54.  **** or any other party as a consequence of the use or disposition of    ****
  55.  **** this software.                                                      ****
  56.  ****                                                                     ****
  57.  **** Patent:                                                             ****
  58.  **** The use of a digital circuit which transmits a signal indicating    ****
  59.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  60.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  61.  **** W. W. Armstrong, President.                                         ****
  62.  ****                                                                     ****
  63.  **** Modification history:                                               ****
  64.  ****                                                                     ****
  65.  **** 20.5.91 Initial Implementation, M. Thomas                           ****
  66.  ****                                                                     ****
  67.  *****************************************************************************/
  68.  
  69.  
  70. /*****************************
  71. * Windows Support File for
  72. * MOSQUITO.C
  73. ******************************/
  74.  
  75. #include <windows.h>
  76. #include <stdlib.h>
  77. #include <stdio.h>
  78. #include "atree.h"
  79. #include "mosqwin.h"
  80. #include "mosqdlg.h"
  81.  
  82. extern NEAR PASCAL main(HWND);
  83. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  84. BOOL FAR PASCAL AboutDlgProc (HWND, WORD, WORD, LONG);
  85.  
  86. HANDLE hInst;
  87. FARPROC lpitAbout;
  88.  
  89. #pragma argsused
  90.  
  91. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  92.                    LPSTR lpszCmdLine, int nCmdShow)
  93.  
  94. {
  95.     static char szAppName[] = "MOSQUITO";
  96.     HWND hwnd;
  97.     MSG msg;
  98.     WNDCLASS wndclass;
  99.  
  100.     if (!hPrevInstance)
  101.      {
  102.      wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  103.      wndclass.lpfnWndProc    = WndProc;
  104.      wndclass.cbClsExtra     = 0;
  105.      wndclass.cbWndExtra     = 0;
  106.      wndclass.hInstance      = hInstance;
  107.      wndclass.hIcon          = LoadIcon(hInstance, "mosqico");
  108.      wndclass.hCursor        = LoadCursor(hInstance, "mosqcur");
  109.      wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
  110.      wndclass.lpszMenuName   = "MENU_RESOURCE";
  111.      wndclass.lpszClassName  = szAppName;
  112.  
  113.      RegisterClass(&wndclass);
  114.      }
  115.  
  116.      hInst = hInstance;
  117.  
  118.      hwnd = CreateWindow(szAppName,                     /* Class */
  119.                          "Mosquito",                    /* Title */
  120.                          WS_OVERLAPPEDWINDOW,           /* Style */
  121.                          CW_USEDEFAULT, CW_USEDEFAULT,  /* x, y */
  122.                          240,180,                       /* xsize, ysize */
  123.                          NULL,                          /* parent */
  124.                          NULL,                          /* class menu */
  125.                          hInstance,                     /* creator */
  126.                          NULL);                         /* Params */
  127.  
  128.  
  129.      ShowWindow(hwnd, nCmdShow);
  130.      UpdateWindow(hwnd);
  131.  
  132.      lpitAbout = MakeProcInstance((FARPROC)AboutDlgProc, hInst);
  133.  
  134.      while (GetMessage(&msg, NULL,0,0))
  135.       {
  136.       TranslateMessage(&msg);
  137.       DispatchMessage(&msg);
  138.       }
  139.      return msg.wParam;
  140. }
  141.  
  142.  
  143. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  144.  
  145.    {
  146.    HANDLE hMenu, hSysMenu;
  147.    static int cRun = 0;
  148.  
  149.    switch (message)
  150.  
  151.     {
  152.  
  153.  
  154.     case WM_COMMAND:
  155.         hMenu = GetMenu(hwnd);
  156.         hSysMenu = GetSystemMenu(hwnd, 0);
  157.         switch (wParam)
  158.             {
  159.             case IDM_EXIT:
  160.                 DestroyWindow(hwnd);
  161.                 break;
  162.  
  163.             case IDM_RUN:
  164.  
  165.                 EnableMenuItem(hMenu, IDM_EXIT, MF_GRAYED);
  166.                 EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED);
  167.                 DrawMenuBar(hwnd);
  168.                 cRun ++;
  169.                 if (!main(hwnd))
  170.                     {
  171.                     cRun --;
  172.                     MessageBeep(0);
  173.                     MessageBox(hwnd,"Mosquito could not infect!", "Mosquito", MB_OK);
  174.                     }
  175.                 cRun --;
  176.                 EnableMenuItem(hMenu, IDM_RUN, MF_ENABLED);
  177.                 if (!cRun)
  178.                     {
  179.                     EnableMenuItem(hMenu, IDM_EXIT, MF_ENABLED);
  180.                     EnableMenuItem(hSysMenu, SC_CLOSE, MF_ENABLED);
  181.                     }
  182.                 DrawMenuBar(hwnd);
  183.                 break;
  184.  
  185.             case IDM_ABOUT:
  186.                 DialogBox(hInst,
  187.                           MAKEINTRESOURCE(IDD_ABOUT),
  188.                           hwnd,
  189.                           lpitAbout);
  190.                 break;
  191.             }
  192.         break;
  193.  
  194.     case WM_DESTROY:
  195.         PostQuitMessage(0);
  196.         break;
  197.  
  198.     default:
  199.         return DefWindowProc(hwnd,message,wParam,lParam);
  200.     }
  201.    return 0L;
  202.    }
  203.  
  204. #pragma argsused
  205.  
  206. BOOL FAR PASCAL AboutDlgProc (HWND hdlg, WORD message, WORD wParam, LONG lParam)
  207.    {
  208.    switch (message)
  209.        {
  210.        case WM_COMMAND:
  211.            EndDialog(hdlg, TRUE);
  212.            return TRUE;
  213.        default:
  214.            return FALSE;
  215.        }
  216.    }
  217.